package platform

import (
	"errors"
	"net/url"

	"gitee.com/wchpub/fnsvr"
)

// 微小用户信息
type QuickDecryptUserInfoResp struct {
	Result bool      `json:"result"`
	Data   *UserInfo `json:"data"`
}

// quick登录解密抖小 微小用户信息
func QuickDecryptUserInfo(encryptedData, sessionKey, iv string) (*UserInfo, error) {

	url := sessionKey +
		"&encryptData=" + url.QueryEscape(encryptedData) +
		"&iv=" + url.QueryEscape(iv)

	resp, err := fnsvr.HttpGetNoParam[QuickDecryptUserInfoResp](url)
	if err != nil {
		return nil, err
	}

	if !resp.Result || resp.Data == nil {
		return nil, errors.New("empty data")
	}

	return resp.Data, nil
}
